package util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Logger {

	private static FileWriter log;

	public Logger(String nameFile) throws IOException {
		log = new FileWriter(new File(nameFile), false);
	}

	public void append(String info, boolean hour) {
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();
		try {
			if (hour) {
				log.write(info + " - " + dateFormat.format(date) + "\n");
			}else
			{
				log.write(info + "\n");
			}
		} catch (IOException e) {
			System.out.println(e);
		}
	}

	public void close() {
		try {
			log.close();
		} catch (IOException e) {
			System.out.println(e);
		}
	}

}
